package com.chen.posp;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.chen.posp.entity.PosTrxRequest;
import com.chen.posp.enums.TrxType;


/**
 * Title: POS交易管理实现
 * @Description:
 * @Copyright: Copyright (c)2010
 * @Company: YeePay
 * @author jun.yu
 */
public class PosTrxManagerImpl implements PosTrxManager {
	private PosRequestReceiveReturnService posRequestReceiveReturnService;

	private Log log = LogFactory.getLog(PosTrxManagerImpl.class);


	public byte[] trxManage(byte[] inputData) {

		log.info("pos input data(Hex):\n" + ISO8583Utile.bytesToHexString(inputData));

		// 1、报文解析
		UnionPayParam trxParam = new UnionPayParam();
		String trxBaseInfo = "";	// 交易基础信息，供日志打印使用
		byte[] data = null;
		String sourceTPDU = "";
		byte[] tpdubyte = new byte[Constant.LEN_POS_TPUD];
		System.arraycopy(inputData, Constant.LEN_POS_MESSAGETYPE, tpdubyte, 0, Constant.LEN_POS_TPUD);
		sourceTPDU = ISO8583Utile.bytesToHexString(tpdubyte);
		try {
			trxParam = posRequestReceiveReturnService.Decoding(inputData, trxParam);
		} catch (Exception e) {
		}

		if (data != null) {
			data = pre8583Message(data, sourceTPDU);
			return data;
		}

		PosTrxRequest trxRequest = new PosTrxRequest();

		trxRequest = getPosTrxRequest(trxParam, inputData);

		if (data != null) {
			data = pre8583Message(data, sourceTPDU);
			return data;
		}

		trxParam.setTrxType(trxRequest.getTrxType());
//		FrpInterfaceDetail frpInterfaceDetail = new FrpInterfaceDetail();
//
//		try {
//			trxBaseInfo = " trxType=" + trxRequest.getTrxType().name() + " posCATI=" + trxRequest.getPosCATI() + " pan=" + trxRequest.getPan() + " trxAmount="
//					+ trxRequest.getTrxAmount() + " posBatch=" + trxRequest.getPosBatch() + " posRequestId=" + trxRequest.getPosRequestId() + " posTrxRequestId="
//					+ trxRequest.getId() + " shopCustomerNumber=" + trxRequest.getShopCustomerNumber();
//
//		} catch (Exception e1) {
//			log.info("trxParam.posCATI: " + trxParam.getCard_accptr_termnl_id());
//			log.error("unknown exception before trxType!", e1);
//			trxParam.setResp_code("96");
//			posReceiveMsgTransform = posReceiveMsgTransformFactory.getServiceMap(trxParam.getPosManufacturer().name());
//			data = processUnControlCondition(trxParam);
//		}
//		log.info("PosTrxStarting params:" + trxBaseInfo);	// 强制日志输出 error

		if (data != null) {
			data = pre8583Message(data, sourceTPDU);
			return data;
		}

		// 校验拨号POS来电号码
//		if (!verifyPhone(trxRequest)) {
//			log.info("+++++++++ verify dailPos fail!");
//			trxParam.setResp_code("96");
//			posReceiveMsgTransform = posReceiveMsgTransformFactory.getServiceMap(trxParam.getPosManufacturer().name());
//			data = processUnControlCondition(trxParam);
//		}

		if (data != null) {
			data = pre8583Message(data, sourceTPDU);
			return data;
		}
		// 2、按交易类型进行交易处理

//		Transaction transaction = transactionFactory.getTransaction(trxRequest.getTrxType().name());
//		data = transaction.execute(trxRequest, trxParam, frpInterfaceDetail);
		data = pre8583Message(data, sourceTPDU);
		return data;
	}

//	private boolean verifyPhone(PosTrxRequest trxRequest) {
//		// 拨号POS来电号码
//		String callPhoneNo = trxRequest.getCallPhoneNo();
//		if (StringUtils.isNotBlank(callPhoneNo)) {
//			// 交易类型
//			TrxType trxType = trxRequest.getTrxType();
//			// 只在消费交易，退货交易,预授权和预授权完成时需要校验来电号码,加上分期付款
//			if (trxType != TrxType.PURCHASE && trxType != TrxType.PURCHASE_REFUND && trxType != TrxType.PRE_AUTHORIZATION
//					&& trxType != TrxType.PRE_AUTHORIZATION_COMPLETION && trxType != TrxType.HIRE_PURCHASE) {
//				return true;
//			} else {
//				// 网点编号
//				String shopCustomerNumber = trxRequest.getShopCustomerNumber();
//				Shop shop = shopService.findByShopCustomerNumber(shopCustomerNumber);
//				if (shop == null) {
//					log.error("Shop is null ! shopCustomerNumber=" + shopCustomerNumber);
//					return false;
//				}
//
//				String newDialPosPhone = shop.getNewBindPhone();
//				String oldDialPosPhone = shop.getOldBindPhone();
//				Date effectTime = shop.getEffectTime();
//
//				// 暂时不考虑来电号码没区号的问题
//				long callPhoneNoForLong = Long.parseLong(callPhoneNo);
//				String callPhoneNoTemp = String.valueOf(callPhoneNoForLong);
//				// 白名单检测
//				for (String writerListNo : callPhoneNoWriteList) {
//					if (writerListNo.endsWith(callPhoneNoTemp) && (writerListNo.indexOf(callPhoneNoTemp) < 2 || callPhoneNoTemp.startsWith("010"))) {
//						log.info("########### callPhoneNo is in whiteList ["+callPhoneNoTemp+"]");
//						return true;
//					}
//				}
//
//				if (StringUtils.isBlank(newDialPosPhone)) {
//					log.error("newDialPosPhone is null ! shopCustomerNumber=" + shopCustomerNumber);
//					return false;
//				}
//
//				if ("######".equals(newDialPosPhone)) {  // 特殊处理
//					return true;
//				}
//
//				if (effectTime == null) {
//					log.error("effectTime is null ! shopCustomerNumber=" + shopCustomerNumber);
//					return false;
//				}
//
//				String usablePhone = ""; // 可用号码
//
//				Date currTime = new Date();
//				if (currTime.before(effectTime)) {// 当前时间在生效时间前，此时旧绑定号码和新绑定号码都可以使用。
//					usablePhone = newDialPosPhone + "," + oldDialPosPhone;
//				} else {// 当前时间为生效时间或之后时，无法使用旧绑定号码，只能使用新绑定号码。
//					usablePhone = newDialPosPhone;
//				}
//				String[] usablePhoneArr = usablePhone.split(",");
//				for (String temp : usablePhoneArr) {
//					temp = temp.trim().replace("-", ""); // 兼容010-12345678类型号码
//					int i = temp.indexOf(callPhoneNoTemp);
//					if (i <= -1) {
//						continue;
//					} else if (i >= 0 && i <= 1) {
//						if (temp.endsWith(callPhoneNoTemp)) {
//							return true;
//						}
//					} else {
//						// 如果是010开头，则callPhone中不附加区号，而设置号码时添加了区号，兼容添加区号的号码
//						if (temp.substring(0, 3).equals("010") && temp.endsWith(callPhoneNoTemp)) {
//							return true;
//						}
//					}
//				}
//				log.error("the number is defferent! callPhoneNumber[" + callPhoneNoTemp + "] , shopPhoneNumber [" + usablePhone + "] ,  shopCustomerNumber = ["
//						+ shopCustomerNumber + "]");
//				return false;
//			}
//		} else {
//			// 拨号POS的电话号码有如不显示来电号码功能，将得不到号码
//			// Pos pos = posService.findByPosCATI(trxRequest.getPosCATI());
//			// // POS机型号
//			// String type = pos.getType();
//			// if(type.equals("NL8080Y") || type.equals("E330")){
//			// log.error("无法得到拨号POS的来电号码，如果电话号码定制有不显示来电号码的功能，请取消.");
//			// return false;
//			// }
//			return true;
//		}
//	}

	private PosTrxRequest getPosTrxRequest(UnionPayParam unionPayParam, byte[] orInputData){

		// 创建POSTRXREQUEST记录

		PosTrxRequest posTrxRequest = new PosTrxRequest();
		posTrxRequest.setInputType(unionPayParam.getPos_entry_mode_code()); // 输入方式
		String track2data = unionPayParam.getTrack_2_data();

		/*
		 * if(!Constant.MESSAGE_SIGN_IN_MTYPE.equals(unionPayParam.getMti()) &&!Constant.MESSAGE_SIGN_OFF_MTYPE.equals(unionPayParam.getMti())
		 * &&!Constant.MESSAGE_SETTLE_MTYPE.equals(unionPayParam.getMti() ){ if(Constant.POS_ENTRY_MODE_CODEA.equals(unionPayParam.getPos_entry_mode_code())){//刷卡，且PIN
		 * 可输入 track2data=unionPayParam.getTrack_2_data(); int i=track2data.indexOf("="); posTrxRequest.setPan(track2data.substring(0, i)); //卡号
		 * posTrxRequest.setPin(unionPayParam.getPin_data()); //密码 posTrxRequest.setTrack2Data(unionPayParam.getTrack_2_data()); //2磁道信息
		 * posTrxRequest.setTrack3Data(unionPayParam.getTrack_3_data()); //3磁道信息 }else
		 * if(Constant.POS_ENTRY_MODE_CODEB.equals(unionPayParam.getPos_entry_mode_code())){//刷卡，无PIN track2data=unionPayParam.getTrack_2_data(); int
		 * i=track2data.indexOf("="); posTrxRequest.setPan(track2data.substring(0, i)); //卡号 posTrxRequest.setTrack2Data(unionPayParam.getTrack_2_data()); //2磁道信息
		 * posTrxRequest.setTrack3Data(unionPayParam.getTrack_3_data()); //3磁道信息 }else{ posTrxRequest.setPan(unionPayParam.getPrimary_acct_num()); //卡号 } }
		 */

		// 对2磁道进行加密
		if (track2data != null) {
			if (track2data.contains("=")) {
				int i = track2data.indexOf("=");
				posTrxRequest.setPan(track2data.substring(0, i)); // 卡号
			} else {
				posTrxRequest.setPan(track2data); // 卡号
			}

			// try {
			// posTrxRequest.setTrack2Data(EncryptUtils.encryptPlainData(track2data));
			// } catch (SecretKeyException e) {
			// posTrxRequest.setTrack2Data(track2data);
			// }
		} else {
			posTrxRequest.setPan(unionPayParam.getPrimary_acct_num()); // 卡号
		}

		posTrxRequest.setPosRequestId(unionPayParam.getSys_trace_audit_num()); // POS流水号
		posTrxRequest.setShopCustomerNumber(unionPayParam.getCard_accptr_id()); // POS商户号
		posTrxRequest.setPosCATI(unionPayParam.getCard_accptr_termnl_id()); // POS终端号

		// posTrxRequest.setPosTrxTime(new Date()); //POS刷卡时间(先暂定用当前时间)
		// posTrxRequest.setCvv2(unionPayParam.getPrimary_acct_num()); //CVV2(目前没有域对应这个属性值)

		posTrxRequest.setPosBatch(unionPayParam.getTransBatchNo());							// 交易批次号
		// posTrxRequest.setInstallmentsPayMark(unionPayParam.getPrimary_acct_num()); //分期付款标志(目前没有)
		posTrxRequest.setProcessingCode(unionPayParam.getProcessing_code());				// 处理码
		posTrxRequest.setServiceCode(unionPayParam.getPos_cond_code());						// 服务代码
		// posTrxRequest.setPosOrderCode(unionPayParam.getPrimary_acct_num()); //POS订单号
		// posTrxRequest.setMessageTypeCode(); //消息状态码
		posTrxRequest.setSourcePosBatch(unionPayParam.getOrg_trans_batch_no());				// 原交易批次号
		posTrxRequest.setSourcePosRequestId(unionPayParam.getOrg_sys_trace_audit_num());	// 原交易流水号/系统跟踪号

		if (!Constant.COD_PIC_SIGNIN_ZT.equals(unionPayParam.getTrx_source())) {// 物流证通的签名不存放原始请求报文
			posTrxRequest.setRequesMessage(ISO8583Utile.bytesToHexString(orInputData)); // 原始请求报文 
		}
		posTrxRequest.setTrxSource(unionPayParam.getTrx_source()); // 交易来源

		if (Constant.MESSAGE_SIGN_IN_MTYPE.equals(unionPayParam.getMti())) {// 签到
			posTrxRequest.setTrxType(TrxType.SIGN_IN);
		} else if (Constant.MESSAGE_SIGN_OFF_MTYPE.equals(unionPayParam.getMti())) {// 签退
			posTrxRequest.setTrxType(TrxType.SIGN_OFF);
		} else if (Constant.MESSAGE_SETTLE_MTYPE.equals(unionPayParam.getMti())) {// 结算
			posTrxRequest.setTrxType(TrxType.SETTLE);
		} else if (Constant.MESSAGE_BATHUP_MTYPE.equals(unionPayParam.getMti())) {// 批上送
			posTrxRequest.setTrxType(TrxType.BATHUP);
		} else if (Constant.MESSAGE_ORDERINQUIRY_MTYPE.equals(unionPayParam.getMti())) {// 订单查询
			posTrxRequest.setTrxType(TrxType.ORDERINQUIRY);
		} else if (Constant.MESSAGE_CODTYPE_MTYPE.equals(unionPayParam.getMti())) {// 通知
			posTrxRequest.setTrxType(TrxType.NOTIFY);
		}else if (Constant.MESSAGE_ORDERCONFIRM_MTYPE.equals(unionPayParam.getMti())){ // 交易确认
			posTrxRequest.setTrxType(TrxType.ORDERCONFIRM);
		}else {
//			TrxTypeDict trxTypeDict = new TrxTypeDict();
//			trxTypeDict = trxTypeDictService.findByMessageTypeAndProcessingCodeAndCondCodeAndMessageTypeCode(unionPayParam.getMti(), unionPayParam.getProcessing_code(),
//					unionPayParam.getPos_cond_code(), unionPayParam.getMsg_type_code());
//			if (trxTypeDict != null) {
//				posTrxRequest.setTrxType(trxTypeDict.getTrxType());
//			}
		}
//
//		Pos pos = null;
//		if (TrxType.SETTLE.equals(posTrxRequest.getTrxType()) || TrxType.BATHUP.equals(posTrxRequest.getTrxType()) || TrxType.SIGN_OFF.equals(posTrxRequest.getTrxType())) {
//			pos = posService.findByPosCATI(unionPayParam.getCard_accptr_termnl_id());
//		} else if (isUnicomTrx(unionPayParam)){
//			log.info("unicom trx uss findByShopCustomerNumberAndPosCATI4Unicom !");
//			pos = posService.findByShopCustomerNumberAndPosCATI4Unicom(unionPayParam.getCard_accptr_id(), unionPayParam.getCard_accptr_termnl_id());
//		} else {
//			pos = posService.findByShopCustomerNumberAndPosCATI(unionPayParam.getCard_accptr_id(), unionPayParam.getCard_accptr_termnl_id());
//		}
//
//		if (pos == null) {
//			log.info("++++++++++++ pos is null ! posCATI=" + unionPayParam.getCard_accptr_termnl_id());
//			throw new PosUnefficientException();
//		}
//
//		if (Constant.MESSAGE_SIGN_IN_MTYPE.equals(unionPayParam.getMti()) || Constant.MESSAGE_SETTLE_MTYPE.equals(unionPayParam.getMti())) {// 签到，结算
//			posTrxRequest.setPosOperator(unionPayParam.getInterna_crecardcompa_code()); // 操作员(只有签到和批结算的时候会上送)
//		} else {
//			if (!PosRunStatus.SIGNED.equals(pos.getRunStatus()) && !Constant.MESSAGE_BATHUP_MTYPE.equals(unionPayParam.getMti())
//					&& !Constant.MESSAGE_SIGN_OFF_MTYPE.equals(unionPayParam.getMti())) {// POS没有进行签到,排除批上送和签退
//				log.info("+++++++  POS is unsigned! posCATI=" + unionPayParam.getCard_accptr_termnl_id());
//				throw new PosUnefficientException();
//			}
//			posTrxRequest.setPosOperator(pos.getPosOperator());
//		}
//		String location = unionPayParam.getCustom_fields();
//		if (StringUtil.notNull(location) && location.length() >= 10) {
//			String lAC = location.substring(0, 5);
//			String cID = location.substring(5);
//			posTrxRequest.setLAC(lAC);
//			posTrxRequest.setCID(cID);
//		}
//
//		posTrxRequestService.create(posTrxRequest);

		return posTrxRequest;
	}
	
	/**
	 * 判断是否是联通交易
	 * 
	 * @param upp
	 * @return
	 */
	private boolean isUnicomTrx(UnionPayParam upp) {
		try {
			if (StringUtils.isBlank(upp.getAddtnl_data_private())) {
				return false;
			}
			String data = new String(ISO8583Utile.hexStringToByte(upp
					.getAddtnl_data_private()));
			if ((data.length() >= 2)
					&& (Constant.UNICOM_TRX_FLAG.equals(data.substring(0, 2)))) {
				return true;
			}
		} catch (Exception e) {
			log.error("isUnicomTrx flag check fail!",e);
		}
		return false;
	}

	private byte[] pre8583Message(byte[] data, String sourceTPDU) {
		if (data == null) {
			log.error("the message return to pos is null !");
			return null;
		}
		byte[] realdata = new byte[data.length];
		byte[] tpdubytes = new byte[Constant.LEN_POS_TPUD];
		System.arraycopy(data, Constant.LEN_POS_MESSAGETYPE, tpdubytes, 0, Constant.LEN_POS_TPUD);
		String returnTPDU = getTPDU(sourceTPDU);
		byte[] realTPDUbytes = new byte[Constant.LEN_POS_TPUD];
		realTPDUbytes = ISO8583Utile.string2Bcd(returnTPDU);
		int startPosition = 0;
		System.arraycopy(data, 0, realdata, startPosition, Constant.LEN_POS_MESSAGETYPE);
		startPosition += Constant.LEN_POS_MESSAGETYPE;
		System.arraycopy(realTPDUbytes, 0, realdata, startPosition, Constant.LEN_POS_TPUD);
		startPosition += Constant.LEN_POS_TPUD;
		System.arraycopy(data, startPosition, realdata, startPosition, data.length - startPosition);
		return realdata;
	}

	private String getTPDU(String TPDU) {
		if (StringUtils.isBlank(TPDU)) {
			log.error("the return message's TPDU is null!");
			return Constant.CONTENT_POS_TPUD;
		}
		String constantMessage = TPDU.substring(0, 2); // 前两位固定
		String front = TPDU.substring(2, 6); // 中间4位数据
		String back = TPDU.substring(6); // 后4位数据
		String newTPDU = constantMessage + back + front;
		return newTPDU;
	}

	private byte[] processUnControlCondition(UnionPayParam unionPayParam) {
		log.info("processUnControlCondition start ! posCATI :[" + unionPayParam.getCard_accptr_termnl_id() + "]");
		try {
			PosTrxRequest posTrxRequest = new PosTrxRequest();
			if (Constant.MESSAGE_SIGN_IN_MTYPE.equals(unionPayParam.getMti())) {// 签到
				posTrxRequest.setTrxType(TrxType.SIGN_IN);
			} else if (Constant.MESSAGE_SIGN_OFF_MTYPE.equals(unionPayParam.getMti())) {// 签退
				posTrxRequest.setTrxType(TrxType.SIGN_OFF);
			} else if (Constant.MESSAGE_SETTLE_MTYPE.equals(unionPayParam.getMti())) {// 结算
				posTrxRequest.setTrxType(TrxType.SETTLE);
			} else if (Constant.MESSAGE_BATHUP_MTYPE.equals(unionPayParam.getMti())) {// 批上送
				posTrxRequest.setTrxType(TrxType.BATHUP);
			} else if (Constant.MESSAGE_ORDERINQUIRY_MTYPE.equals(unionPayParam.getMti())) {// 订单查询
				posTrxRequest.setTrxType(TrxType.ORDERINQUIRY);
			} else if (Constant.MESSAGE_CODTYPE_MTYPE.equals(unionPayParam.getMti())) {// 通知
				posTrxRequest.setTrxType(TrxType.NOTIFY);
			} else {
//				TrxTypeDict trxTypeDict = new TrxTypeDict();
//				trxTypeDict = trxTypeDictService.findByMessageTypeAndProcessingCodeAndCondCodeAndMessageTypeCode(unionPayParam.getMti(),
//						unionPayParam.getProcessing_code(), unionPayParam.getPos_cond_code(), unionPayParam.getMsg_type_code());
//				if (trxTypeDict != null) {
//					posTrxRequest.setTrxType(trxTypeDict.getTrxType());
//				}
			}
			log.info("processUnControlCondition , trxType [" + posTrxRequest.getTrxType() + "]");

//			if (TrxType.PURCHASE.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.purchase(unionPayParam);
//			} else if (TrxType.BALANCE_INQUIRY.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.availableFundsInquiry(unionPayParam);
//			} else if (TrxType.AVAILABLE_FUNDSINQUIRY.equals(posTrxRequest)) {
//				return posReceiveMsgTransform.availableFundsInquiry(unionPayParam);
//			} else if (TrxType.SETTLE.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.settle(unionPayParam);
//			} else if (TrxType.BATHUP.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.BatchUpSide(unionPayParam);
//			} else if (TrxType.PURCHASEREVERSAL.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.backOut(unionPayParam);
//			} else if (TrxType.PURCHASEVOID.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.purchaseRepeal(unionPayParam);
//			} else if (TrxType.PURCHASEVOIDREVERSAL.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.purchaseRepealBackOut(unionPayParam);
//			} else if (TrxType.PURCHASE_REFUND.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.purchaseRefund(unionPayParam);
//			} else if (TrxType.SIGN_IN.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.signIn(unionPayParam);
//			} else if (TrxType.SIGN_OFF.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.signOut(unionPayParam);
//			} else if (TrxType.ORDERINQUIRY.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.OrderInquiry(unionPayParam);
//			} else if (TrxType.NOTIFY.equals(posTrxRequest.getTrxType())) {
//				if (Constant.COD_SIGNORDER_NEWLAND.equals(unionPayParam.getTrx_source()) || Constant.COD_SIGNORDER_ZT.equals(unionPayParam.getTrx_source())
//						|| Constant.COD_SIGNORDER_NEWLAND_PD.equals(unionPayParam.getTrx_source()) || Constant.COD_HK_SIGN_ORDER.equals(unionPayParam.getTrx_source())
//						|| Constant.COD_HK_MANUAL_ORDER_SIGN.equals(unionPayParam.getTrx_source())
//						|| Constant.COD_ORDEREXCEPTION_NEWLAND.equals(unionPayParam.getTrx_source())
//						|| Constant.COD_ORDEREXCEPTION_ZT.equals(unionPayParam.getTrx_source())
//						|| Constant.COD_ORDEREXCEPTION_NEWLAND_PD.equals(unionPayParam.getTrx_source())
//						|| Constant.COD_HK_EXCEPTION.equals(unionPayParam.getTrx_source()) || Constant.CHAIN_PREPAIDCARD_PIN_MODIFY.equals(unionPayParam.getTrx_source())) {
//					return posReceiveMsgTransform.CodSignin(unionPayParam);
//				} else if (Constant.COD_PIC_SIGNIN_ZT.equals(unionPayParam.getTrx_source())) {
//					return posReceiveMsgTransform.CodName(unionPayParam);
//				} else if (Constant.DISCOUNT_PURCHASE.equals(unionPayParam.getTrx_source()) || Constant.COUPON_PURCHASE.equals(unionPayParam.getTrx_source())) {
//					return posReceiveMsgTransform.checkMobile(unionPayParam);
//				} else if (Constant.KEEPBOOK.equals(unionPayParam.getTrx_source())) {
//					return posReceiveMsgTransform.keepbook(unionPayParam);
//				} else if (Constant.HXMKL_CUSTOMER_QUERY.equals(unionPayParam.getTrx_source())) {
//					return posReceiveMsgTransform.customerQuery(unionPayParam);
//				}
//			} else if (TrxType.PRE_AUTHORIZATION.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.preAuthorization(unionPayParam);
//			} else if (TrxType.PRE_AUTHORIZATION_REVERSAL.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.preAuthorizationReversal(unionPayParam);
//			} else if (TrxType.PRE_AUTHORIZATIONVOID.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.preAuthorizationVoid(unionPayParam);
//			} else if (TrxType.PRE_AUTHORIZATIONVOIDREVERSAL.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.preAuthorizationVoidReversal(unionPayParam);
//			} else if (TrxType.PRE_AUTHORIZATION_COMPLETION.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.preAuthorizationCompletion(unionPayParam);
//			} else if (TrxType.PRE_AUTHORIZATION_COMPLETION_REVERSAL.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.preAuthorizationCompletionReversal(unionPayParam);
//			} else if (TrxType.PRE_AUTHORIZATION_COMPLETION_VOID.equals(posTrxRequest)) {
//				return posReceiveMsgTransform.preAuthorizationCompletionVoid(unionPayParam);
//			} else if (TrxType.PRE_AUTHORIZATION_COMPLETION_VOIDREVERSAL.equals(posTrxRequest.getTrxType())) {
//				return posReceiveMsgTransform.preAuthorizationCompletionVoidReversal(unionPayParam);
//			}
//			log.info("processUnControlCondition end !  posCATI :[" + unionPayParam.getCard_accptr_termnl_id() + "]");
			return new byte[] { 1 };
		} catch (Exception e) {
			log.error("processUnControlCondition error!", e);
			return new byte[] { 1 };
		}
	}

	


}
